home *** CD-ROM | disk | FTP | other *** search
- // AFD.H
- // (C) Anubis Software Agosto 1995.
- // Esta librería sirve para el uso de automatas finitos deterministas.
- #ifndef AFD_H
- #define AFD_H
-
- // NOTAS
- // =====
-
- // --------------------------------------+
- // Librerías Borland C++ |
- // --------------------------------------+
- #include <stdlib.h>
-
- // --------------------------------------+
- // Librerías Anubis Software |
- // --------------------------------------+
- #include "mdefs.h"
-
- // --------------------------------------+
- // Definición de constantes |
- // --------------------------------------+
- #define GENERAL 255
-
- // --------------------------------------+
- // Declaracion de prototipos |
- // --------------------------------------+
-
- typedef struct {
- void *NodoFin; // Es un apuntador a AFDNodo
- void *Siguiente; // Es un apuntador a AFDArista
- unsigned char Caracter;
- void *Apuntador;
- } AFDArista;
-
- typedef struct {
- boolean Terminal;
- AFDArista *Aristas;
- AFDArista *General;
- void *Apuntador;
- } AFDNodo;
-
- typedef struct {
- AFDNodo *Inicio,
- *Actual;
- } AFD;
-
- // -----------------------------------------------+
- // Macros de la libreria |
- // -----------------------------------------------+
- #define AFDSetTerminal(x) (*x).Terminal = TRUE
- #define AFDSetInicio(x,y) (*x).Inicio = y
- #define AFDResetea(x) (*x).Actual = (*x).Inicio
- #define AFDEsTerminal(x) ((*x).Terminal)
- #define AFDFin(x) ((*(*x).Actual).Terminal)
- // -----------------------------------------------+
- // Declaración e implementación de las funciones |
- // -----------------------------------------------+
-
- AFDNodo *AFDAnula(AFD *automat)
- {
- AFDNodo *nodo;
- nodo= (AFDNodo *) malloc (sizeof(AFDNodo));
- (*nodo).Aristas = NULL;
- (*nodo).General = NULL;
- (*nodo).Terminal = FALSE;
- (*automat).Inicio = nodo;
- (*automat).Actual = nodo;
- return(nodo);
- }// end AFDAnula
-
-
- AFDNodo *AFDCrea(AFDNodo *nodobase, unsigned char acontecimiento, void *apuntador)
- {
- AFDNodo *nodo;
- AFDArista *arista;
- nodo = (AFDNodo *) malloc (sizeof(AFDNodo));
- (*nodo).Aristas = NULL;
- (*nodo).General = NULL;
- (*nodo).Apuntador = NULL;
- (*nodo).Terminal = FALSE;
- arista = (AFDArista *) malloc (sizeof (AFDArista));
- if( acontecimiento != GENERAL) {
- (*arista).Siguiente = (*nodobase).Aristas;
- (*nodobase).Aristas = arista;
- } else {
- (*arista).Siguiente = NULL;
- (*nodobase).General = arista;
- }// end if
- (*arista).Caracter= acontecimiento;
- (*arista).NodoFin = nodo;
- (*arista).Apuntador=apuntador;
- return(nodo);
- }// end AFDCrea
-
-
- AFDArista *AFDAnade(AFDNodo *nodobase, unsigned char acontecimiento, AFDNodo *nodofin)
- {
- AFDArista *arista;
- arista = (AFDArista *) malloc (sizeof (AFDArista));
- (*arista).Caracter = acontecimiento;
- (*arista).NodoFin = nodofin;
- (*arista).Apuntador = NULL;
- if ( acontecimiento != GENERAL) {
- (*arista).Siguiente = (*nodobase).Aristas;
- (*nodobase).Aristas = arista;
- } else {
- (*arista).Siguiente = NULL;
- (*nodobase).General = arista;
- }// end if
- return(arista);
- }// end AFDAnade
-
-
- AFDArista *AFDAcontecimiento(AFD *automat, char acont, AFDNodo **nodo)
- {
- AFDArista *aaux;
- aaux = (*((*automat).Actual)).Aristas;
- while ( (aaux != NULL) && ( (*aaux).Caracter != acont))
- aaux = (*aaux).Siguiente;
- if ( aaux != NULL ) {
- (*automat).Actual = (*aaux).NodoFin;
- *nodo = (*aaux).NodoFin;
- return(aaux);
- } else {
- aaux = (*((*automat).Actual)).General;
- (*automat).Actual = (*aaux).NodoFin;
- *nodo = (*aaux).NodoFin;
- return(aaux);
- }// end if
- }// end AFDAcontecimiento.
-
- #endif
-